/*
 * @Author: 姚沈阳 11500793+yao-shenyang@user.noreply.gitee.com
 * @Date: 2023-10-31 11:37:32
 * @LastEditors: 姚沈阳 11500793+yao-shenyang@user.noreply.gitee.com
 * @LastEditTime: 2023-11-04 08:59:01
 * @FilePath: \票务管理\app\ticketing-management\server\app\controller\ticket.js
 * @Description: 
 * qq1908552310
 */
'use strict';

const { Controller } = require('egg');

class TicketController extends Controller {
    async index() {
        let result = await this.ctx.service.ticket.index()
        this.ctx.body = {
            code: 200,
            message: "查询成功",
            data: result
        }
    }
    async create() {
        console.log(this.ctx.request.body)
        let result = await this.ctx.service.ticket.create(this.ctx.request.body)
        this.ctx.body = {
            code: 200,
            message: "新增成功"
        }
    }


    async update() {
        console.log(this.ctx.request.body)
        let result = await this.ctx.service.ticket.update(this.ctx.request.body)
        if (result.affectedRows == 1) {
            this.ctx.body = {
                code: 200,
                message: "编辑成功"
            }
        } else {
            this.ctx.body = {
                code: 400,
                message: "编辑失败"
            }
        }

    }


    // 删除
    async destroy() {
        console.log(this.ctx.params)
        let result = await this.ctx.service.ticket.destroy(this.ctx.params)
        console.log(result.affectedRows, "result")
        if (result.affectedRows == 1) {
            this.ctx.body = {
                code: 200,
                message: '删除成功'
            }
        } else {
            this.ctx.body = {
                code: 400,
                message: '删除失败'
            }
        }

    }
}

module.exports = TicketController;
